<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="myschool.util.MybatisUtil" %>
<%@ page import="myschool.entity.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="myschool.dao.GradeDao" %>
<%@ page import="myschool.entity.Grade" %>
<%@ page import="myschool.dao.SubjectDao" %>
<%@ page import="myschool.entity.Subject" %>
<%@ page import="myschool.service.SubjectService" %>
<%@ page import="myschool.entity.Page" %>
<%@ page import="myschool.util.StrUtil" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <style>
        .hide{
            pointer-events: none;
            color: gray;
        }
    </style>
</head>
<body>
<%@include file="/checkLogin.jsp"%>

<div>
    <%
        int pageNo= StrUtil.toInt(request.getParameter("pageNo"),1);
        pageNo=pageNo<1?1:pageNo;
        String sname=StrUtil.toStr(request.getParameter("subjectname"));
        Page<Subject> p = SubjectService.ME.page(pageNo, Page.PAGESIZE,sname);
    %>
    <form action="subject.jsp">
        <input name="subjectname" value="<%=sname%>" placeholder="课程名"/>
        <input type="submit" value="搜索"/>
    </form>
    <a href="addSubject.jsp"> <input type="button" value="添加新课程"></a>
</div>

<table border="1" width="85%">
    <tr bgcolor="#d3d3d3">
        <th>编号</th>
        <th>课程名</th>
        <th>课时</th>
        <th>年级</th>
        <th>操作</th>
    </tr>
    <%


        for (Subject subject : p.getData()) {
    %>
    <tr>
        <td><%=subject.getId()%>
        </td>
        <td><%=subject.getSubjectname()%>
        </td>
        <td><%=subject.getClasshour()%>
        </td>
        <td><%-- <%=subject.getGradeid()%>--%>
            <%=subject.getGname()%>
        </td>
        <td><a href="updateSubject.jsp?id=<%=subject.getId()%>">编辑</a>
            &nbsp;&nbsp;
        <a onclick="return confirm('真的要删除这门课?')" href="delsubject.jsp?id=<%=subject.getId()%>">删除</a></td>
    </tr>
    <%}%>

</table>
<p>
    <a href="subject.jsp?pageNo=1&subjectname=<%=sname%>">首页</a>
    <a  <% if(pageNo<=1)out.print("class='hide'");%> href="subject.jsp?pageNo=<%=pageNo-1%>&subjectname=<%=sname%>">上一页</a>
    <a  <% if(pageNo>=p.getPageTotal())out.print("class='hide'");%> href="subject.jsp?pageNo=<%=pageNo+1%>&subjectname=<%=sname%>">下一页</a>
    <a href="subject.jsp?pageNo=<%=p.getPageTotal()%>&subjectname=<%=sname%>">尾页</a>
</p>
</body>
</html>
